"""

    通过multiprocessing运行两个并行进程

"""

import time
from multiprocessing import Process


def count(count_to):
    start = time.time()
    counter = 0
    while counter < count_to:
        counter += 1
    end = time.time()
    print(f"计算{count_to}一共花费时间为：{end - start}s")
    return counter


if __name__ == '__main__':
    start_time = time.time()
    # 创建进程运行倒计时函数。
    to_one_hundred_million = Process(target=count, args=(100000000,))
    to_two_hundred_million = Process(target=count, args=(200000000,))
    # 启动进程，这个方法将立即返回
    to_one_hundred_million.start()
    to_two_hundred_million.start()
    # 等待该进程执行完成，这个方法会一直阻塞，直到进程完成
    to_one_hundred_million.join()
    to_two_hundred_million.join()

    end_time = time.time()

    print(f"总共花费时间为：{end_time - start_time}s")
